<template>
	<div>
		<span>
			<font class="font" size="5" color="grey">患者挂号费用查询</font>
		</span>
		<el-divider></el-divider>
		<el-form :inline="true" :model="formInline" class="demo-form-inline">
			<el-form-item label="就诊卡ID:" required="">
				<el-input v-model="formInline.idnumber" placeholder="请输入就诊卡ID"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="getregistermoney()">搜索</el-button>
			</el-form-item>
		</el-form>
		<el-table :data="registermoneydata" border show-summary :summary-method="getSummaries3" show-summary
			style="width: 100%;background-color: #ddf3ff;">
			<el-table-column prop="num" label="挂号单号" width="180" style="background-color: #aaffff;">
			</el-table-column>
			<el-table-column prop="name" label="姓名">
			</el-table-column>
			<el-table-column prop="idnumber" label="就诊卡ID">
			</el-table-column>
			<el-table-column prop="kind" label="号别">
			</el-table-column>
			<el-table-column prop="state" label="状态">
			</el-table-column>
			<el-table-column prop="money" label="消费金额">
			</el-table-column>
		</el-table>
	</div>
</template>
<script>
	import {
		showMsgTitle
	} from '@/utils/api'
	import {
		showMsgConfirm
	} from '@/utils/api'
	import {
		getRequest
	} from '@/utils/api'
	import {
		postRequest
	} from '@/utils/api'
	import {
		uploadFileRequest
	} from '@/utils/api'
	import {
		putRequest
	} from '@/utils/api'
	import {
		deleteRequest
	} from '@/utils/api'
	import {
		showConstants
	} from '@/utils/api'
	import {
		mapMutations
	} from "vuex";
	export default {
		data() {
			return {
				formInline: {
					idnumber: '',
				},
				registermoneydata: []
			}
		},
		methods: {
			getregistermoney() {
				this.$axios.get('http://localhost:8081/idregister?idnumber=' + this.formInline.idnumber).then((result) => {
					console.log(result.data);
					this.registermoneydata = result.data
				}).catch((err) => {
					console.log(error);
				});
			},
			getSummaries3(param) {
				const {
					columns,
					data
				} = param;
				const sums = [];
				columns.forEach((column, index) => {
					if (index === 0) {
						sums[index] = '总价';
						return;
					}

					if (index === 1) {
						sums[index] = ' ';
						return;
					}

					if (index === 2) {
						sums[index] = ' ';
						return;
					}

					if (index === 3) {
						sums[index] = ' ';
						return;
					}

					if (index === 4) {
						sums[index] = ' ';
						return;
					}
					const values = data.map(item => Number(item[column.property]));
					if (!values.every(value => isNaN(value))) {
						sums[index] = values.reduce((prev, curr) => {
							const value = Number(curr);
							if (!isNaN(value)) {
								return prev + curr;
							} else {
								return prev;
							}
						}, 0);
						sums[index] += ' 元';
					} else {
						sums[index] = 'N/A';
					}
				});
				return sums;
			}
		}
	}
</script>

<style>
	.font {
		margin-bottom: 20px;
	}
</style>
